<script setup>
import HomeCategory from '@/views/Home/components/HomeCategory.vue'
import HomeBanner from './components/HomeBanner.vue'
import HomePanel from '@/views/Home/components/HomePanel.vue'
import { onMounted, ref } from 'vue'
import HomeGoods from '@/views/Home/components/HomeGoods.vue'
import { getHomeGoodsList, getHomeHotGoodsList, getHomeNewGoodsList } from '@/apis/goods.js'
import HomeProduct from './components/HomeProduct.vue'

const goodsNewList = ref([])
const homeHotGoods = ref([])
const homeGoodsList = ref([])

onMounted(async () => {
  goodsNewList.value = await getHomeNewGoodsList(4)
  homeHotGoods.value = await getHomeHotGoodsList(4)
  homeGoodsList.value = await getHomeGoodsList()
})
</script>

<template>
  <div class="home">
    <div class="w category-banner">
      <HomeCategory class="home-category"></HomeCategory>
      <HomeBanner class="home-banner"></HomeBanner>
    </div>
    <div class="w new-goods">
      <HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
        <template #content>
          <ul class="item-list">
            <li v-for="item in goodsNewList">
              <HomeGoods :goods="item"></HomeGoods>
            </li>
          </ul>
        </template>
      </HomePanel>
    </div>
    <div class="w new-goods">
      <HomePanel title="人气推荐" sub-title="人气推荐 好多商品">
        <template #content>
          <ul class="item-list">
            <li v-for="item in homeHotGoods">
              <HomeGoods :goods="item"></HomeGoods>
            </li>
          </ul>
        </template>
      </HomePanel>
    </div>
    <div class="w" v-if="homeGoodsList.length">
      <HomeProduct v-for="item in homeGoodsList" :key="item.id" :item="item" />
    </div>
  </div>
</template>

<style scoped>
.category-banner {
  position: relative;
  height: 360px;
  .home-category {
    z-index: 999;
    height: 100%;
    width: 100%;
    position: relative;
  }
  .home-banner {
    z-index: 998;
    position: absolute;
    height: 100%;
    width: 100%;
    left: 0;
    top: 0;
  }
}
.new-goods {
  ul {
    display: flex;
    li {
      flex: 1;
    }
  }
}
</style>
